package com.abe.jmcl.android.share;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.abe.jmcl.R;
import com.abe.jmcl.base.ManagerAPP;
import com.abe.jmcl.utils.NormalUtils;
import com.abe.jmcl.utils.ToastUtils;
import com.abeframe.core.base.MVPBaseActivity;
import com.abeframe.core.base.MVPBasePresenter;
import com.google.gson.Gson;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.Map;

import butterknife.OnClick;

public class UMengShowActivity extends MVPBaseActivity {

    @Override
    protected MVPBasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int getThemeResId() {
        return 0;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_share_umeng;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected void initDatas() {

    }

    @OnClick(R.id.linear_login_sina_container)
    public void onSinaClicked(View view) {
        UMShareAPI.get(ManagerAPP.getContext()).getPlatformInfo(this, SHARE_MEDIA.SINA, authListener);
    }

    @OnClick(R.id.tv_xieyi)
    public void onXiyiClicked(View view) {
        ToastUtils.showShort(R.string.string_login_xieyi);
    }

    UMAuthListener authListener = new UMAuthListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
            NormalUtils.w(share_media.getName());
        }

        @Override
        public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
            NormalUtils.w(share_media.getName() + "授权登录成功");
            NormalUtils.w("登录用户：" + new Gson().toJson(map));
        }

        @Override
        public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
            NormalUtils.w(share_media.getName() + "授权登录失败");
            NormalUtils.w(throwable.getMessage());
        }

        @Override
        public void onCancel(SHARE_MEDIA share_media, int i) {
            NormalUtils.w(share_media.getName() + "授权登录取消");
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);//完成回调
    }
}
